<template>
	<dt-main-body v-model="labelPosition">
		<div class="location">
			<el-breadcrumb separator-class="el-icon-arrow-right">
				<el-breadcrumb-item>
					<i class="iconfont icon-home"></i>
					管理中心
				</el-breadcrumb-item>
				<el-breadcrumb-item>系统管理</el-breadcrumb-item>
				<el-breadcrumb-item>商户设置</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
				
		<div class="content-box">
			<el-form ref="editForm" :model="model" :rules="rules" :label-position="labelPosition" label-width="120px">
				<el-tabs v-model="activeName" type="card">
					<el-tab-pane label="配置信息" name="info">
						<div class="tab-content">
							<el-form-item prop="regStatus" label="入驻设置">
								<el-radio-group v-model="model.regStatus">
									<el-radio-button label="0">开放申请</el-radio-button>
									<el-radio-button label="1">关闭申请</el-radio-button>
								</el-radio-group>
							</el-form-item>
							<el-form-item prop="regVerify" label="入驻审核">
								<el-radio-group v-model="model.regVerify">
									<el-radio-button label="0">无须审核</el-radio-button>
									<el-radio-button label="1">人工审核</el-radio-button>
								</el-radio-group>
							</el-form-item>
							<el-form-item label="许可协议">
								<el-switch :active-value="1" :inactive-value="0" v-model="model.regRules"></el-switch>
							</el-form-item>
							<el-form-item prop="regRulesTxt" label="协议内容">
								<el-input type="textarea" :rows="5" v-model="model.regRulesTxt" placeholder="必填，支持HTML"></el-input>
							</el-form-item>
						</div>
					</el-tab-pane>
				</el-tabs>
			</el-form>
		</div>
				
		<div class="footer-box">
			<div class="footer-btn">
				<el-button type="primary" @click="submitForm">确认保存</el-button>
				<el-button plain @click="$common.back()">返回上一页</el-button>
			</div>
		</div>
	</dt-main-body>
</template>

<script>
	export default {
		data() {
			return {
				activeName: 'info',//当前选项卡
				labelPosition: 'right',//表单对齐方式
				model: {
					regStatus: 0,
					regVerify: 0,
					regMsgStatus: 0,
					regMsgTxt: null,
					regKeywords: null,
					regCtrl: 0,
					regCodeCtrl: 0,
					regCodeLength: 0,
					regSmsExpired: 0,
					regEmailExpired: 0,
					regRules: 0,
					regRulesTxt: null,
					pointCashRate: 0,
					pointLoginNum: 0
				},
				rules: {
					regStatus: [
						{ required: true, message: '注册设置不可为空', trigger: 'blur' }
					],
					regVerify: [
						{ required: true, message: '注册审核不可为空', trigger: 'blur' }
					],
					regMsgStatus: [
						{ required: true, message: '欢迎消息不可为空', trigger: 'blur' }
					],
					regMsgTxt: [{
						required: true, message: '短消息内容不可为空', trigger: 'blur'
					}],
				}
			}
		},
		methods: {
			//初始化数据
			initData() {
				let _this = this; //当前页面
				_this.$api.request({
					url: '/admin/setting/merchantconfig',
					loading: true,
					success(res) {
						//赋值给model
						Object.keys(_this.model).forEach(key => { _this.model[key] = res.data[key] });
					}
				});
			},
			//提交表单
			submitForm() {
				let _this = this; //当前页面
				//多个表单验证
				const f1 = new Promise((resolve, reject) => {
					_this.$refs['editForm'].validate((valid) => {
						if (valid) resolve()
					});
				});
				Promise.all([f1]).then(() => {
					_this.$api.request({
						method: 'put',
						url: '/admin/setting/merchantconfig',
						data: _this.model,
						loading: true,
						successMsg: '商户置已修改成功',
						success(res) {
							//可写回调处理
						}
					});
				})
			},
		},
		created() {
			this.initData();
		}
	}
</script>